package com.yxj06;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;

public class ArrayListDemo {
    public static void main(String[] args) {
        //创建ArrayList集合对象
        ArrayList<Student> array = new ArrayList<Student>();
        //创建学生对象
        Student s1 = new Student("yyy",1);
        Student s2 = new Student("xxx",2);
        Student s3 = new Student("jjj",3);
        //把学生添加到集合
        array.add(s1);
        array.add(s2);
        array.add(s3);
        //迭代器遍历
        Iterator<Student> it = array.iterator();
        while (it.hasNext()) {
            Student s = it.next();
            System.out.println(s.getName()+","+s.getAge());
        }
        System.out.println("-----------");
        for(int i = 0; i < array.size(); i++) {
            Student s = array.get(i);
            System.out.println(s.getName()+","+s.getAge());
        }
        System.out.println("-------------");
        for(Student s : array) {
            System.out.println(s.getName()+","+s.getAge());
        }
    }
}
